
/**
 * 解析时间戳获取正确时间
 * @param time 时间戳
 * @returns {string} 解析后的时间
 */
function getLocalTime(time) {
    var datetime = new Date();
    datetime.setTime(time);
    var year = datetime.getFullYear();
    var month = datetime.getMonth() + 1;
    var date = datetime.getDate();
    var hour = datetime.getHours();
    var minute = datetime.getMinutes();
    var second = datetime.getSeconds();
    // var mseconds = datetime.getMilliseconds();
    return year + "-" + month + "-" + date+" "+hour+":"+minute+":"+second;
}

layui.config({
    base: '/static/js/layuiModulesEX/'
});
layui.use(['paging','form'], function() {
    var $ = layui.jquery,
        paging = layui.paging(),
        layerTips = parent.layer === undefined ? layui.layer : parent.layer, //获取父窗口的layer对象
        layer = layui.layer, //获取当前窗口的layer对象
        form = layui.form();

    //获取全部岗位信息
    axios.get('/PositionType/findAll')
        .then(function (response) {
            for (var i = 0; i < response.data.data.length; i++){
                positionTypes[response.data.data[i].id] = response.data.data[i].posname;
            }
            console.log(positionTypes);
        })
        .catch(function (response) {
            console.log(response);
        });
    paging.init({
        openWait: true,
        url:'/recruitInfo/findByCondition',
        elem: '#content', //内容容器
        params: { //发送到服务端的参数
            publisherid:publisherid
        },
        contentType : "application/json; charset=utf-8",
        type: 'POST',
        tempElem: '#tpl', //模块容器
        pageConfig: { //分页参数配置
            elem: '#paged', //分页容器
            pageSize: 3 //分页大小
        },
        success: function() { //渲染成功的回调
            //alert('渲染成功');
        },
        fail: function(msg) { //获取数据失败的回调
            //alert('获取数据失败')
        },
        complate: function() { //完成的回调
            //alert('处理完成');

            //重新渲染复选框
            form.render('checkbox');
            form.on('checkbox(allselector)', function(data) {
                var elem = data.elem;
                $('#content').children('tr').each(function() {
                    var $that = $(this);
                    //全选或反选
                    $that.children('td').eq(0).children('input[type=checkbox]')[0].checked = elem.checked;
                    form.render('checkbox');
                });
            });

            //绑定所有编辑按钮事件
            $('#content').children('tr').each(function() {
                //获取每行记录的id值
                var $that = $(this).children('td:last-child');
                var id = $that.children('a[data-opt=more]').data('id');

                $that.children('a[data-opt=more]').on('click', function() {
                    vm.show = false;
                    axios.get('/recruitInfo/find/'+id)
                        .then(function (response) {
                            console.log(response.data.data);
                            vm.recruitinfo = response.data.data;
                        })
                        .catch(function (response) {
                            console.log(response);
                        });
                });

                $that.children('a[data-opt=delete]').on('click', function() {
                    layer.confirm('确认删除？',function (index) {
                        axios.get('/recruitInfo/remove/'+id)
                            .then(function (response) {
                                console.log(response);
                            })
                            .catch(function (response) {
                                console.log(response);
                            });
                        layer.close(index);
                        location.reload();

                    });

                    // var id = $that.children('td:fisrt-child').children('input[type=checkbox]').data('id');
                    // layer.msg(id);
                    // layer.msg(id);
                });



            });

        }
    });
    //获取所有选择的列
    $('#getSelected').on('click', function() {
        var names = '';
        $('#content').children('tr').each(function() {
            var $that = $(this);
            var $cbx = $that.children('td').eq(0).children('input[type=checkbox]')[0].checked;
            if($cbx) {
                var n = $that.children('td:last-child').children('a[data-opt=edit]').data('name');
                names += n + ',';
            }
        });
        layer.msg('你选择的名称有：' + names);
    });
    //搜索
    $('#search').on('click', function() {
        paging.get({
            title:$('#searchVal').val(),
            publisherid:publisherid
        });
        parent.layer.alert('你点击了搜索按钮')
    });

    var vm = new Vue({
        el:'#Vue',
        data:{
            show:true,
            recruitinfo:{
                publisherid:publisherid
            }
        },
        methods:{
            /**
             * 添加按钮
             */
            add:function () {
                vm.show=false;
                //重置数据并清除脏数据 默认为提交状态
                vm.recruitinfo={state:2,publisherid:publisherid};
            },
            /**
             * 暂时保存
             */
            temporarilySaved:function () {
                vm.recruitinfo.state = 1;
                vm.saveOrUpdate();
            },
            /**
             * 查询按钮
             */
            search:function () {
                paging.get({
                    title:$('#searchVal').val()
                });
            },
            /**
             * 插入或更新数据库记录
             */
            saveOrUpdate:function () {
                var url = vm.recruitinfo.id == null ? "/recruitInfo/add" : "/recruitInfo/modify";
                axios.post(url,vm.recruitinfo)
                    .then(function (response) {
                        layer.msg(response.data.message,{time:1500},function () {
                            if (response.data.success){
                                vm.reload();
                            }
                        });

                    })
                    .catch(function (response) {
                        console.log(response);
                    })
            },
            reload:function () {
                vm.show=true;
                paging.get();
            }
        }
    });

});